﻿//-----------------------------------------------------------------------
// <copyright file="TumblrApiFactory.cs" company="OpenSource">
//     All code is Microsoft Public License (Ms-PL)
// </copyright>
// <history>
// 2013.02  Created         Chris Hand
// </history>
//-----------------------------------------------------------------------
namespace OpenSource.TumblrAPI
{
    using System;
    using OpenSource.TumblrAPI.DataObjects;
    using OpenSource.TumblrAPI.Interfaces;
    using OpenSource.TumblrAPI.Support;

    /// <summary>
    /// Creates instances of the Tumblr API classes. 
    /// At the moment, we only support Web calls and V2 API, so we will assume that the Tumblr property
    /// of the TumblrSettings class is corrct for our implementation.  In the future, we might want to do 
    /// checks and to determine which version of the API to return.
    /// </summary>
    public static class TumblrApiFactory
    {
        public static TumblrSettings CreateSettings(string apiKey)
        {
            return new TumblrSettings()
            {
                ApiKey = apiKey,
                Tumblr = "http://api.tumblr.com/v2/",
                Log = new NullLogger()
            };
        }

        public static ITumblrBasic CreateTumblrBasic(TumblrSettings settings)
        {
            ITumblrClient client = TumblrApiFactory.CreateClient(settings);
            ITumblrParser parser = TumblrApiFactory.CreateParser(settings.Log);
            return new ApiV2.TumblrBasic(client, parser, settings.Log);
        }

        public static ITumblrBlog CreateTumblrBlog(TumblrSettings settings)
        {
            return new ApiV2.TumblrBlog();
        }

        public static ITumblrPost CreateTumblrPost(TumblrSettings settings)
        {
            return new ApiV2.TumblrPost();
        }

        public static ITumblrUser CreateTumblrUser(TumblrSettings settings)
        {
            return new ApiV2.TumblrUser();
        }

        private static ITumblrClient CreateClient(TumblrSettings settings)
        {
            return new ApiV2.WebTumblrClient(new Uri(settings.Tumblr), settings.ApiKey);
        }

        private static ITumblrParser CreateParser(ILogger logger)
        {
            return new ApiV2.JsonResponseParser(logger);
        }
    }
}
